{% import "components/home.html" as home with context %}
{% import "components/problem.html" as problem with context %}
{% extends "layout/basic.html" %}
{% block content %}
{{ set(UiContext, 'udoc', udoc) }}
<style>
  .user-profile-bg {
    background-image: url("{{ udoc.backgroundImage }}"), url("/components/profile/backgrounds/1.jpg");
  }
</style>
<div class="row">
  <div class="medium-9 columns">
    <div class="section">
      <div class="profile-header user-profile-bg">
        <div class="profile-header__content">
          <div class="media">
            <div class="media__left">
              <img src="{{ avatarUrl(udoc.avatar, 120) }}" width="120" height="120" class="large user-profile-avatar">
            </div>
            <div class="media__body profile-header__main">
              <h1>
                {% if udoc.realname_flag == 2 %}
                <span class="icon icon-user"></span>
                {% elif udoc.realname_flag == 1%}
                <span class="icon icon-star"></span>
                {% endif %}
            
                {% if handler.user.hasPerm(perm.PERM_VIEW_DISPLAYNAME) and udoc.realname_name %}
                  {{ udoc.realname_name }} ({{ udoc.uname }})
                {% elif handler.user.hasPerm(perm.PERM_VIEW_DISPLAYNAME) and udoc.displayName and udoc.displayName != udoc.uname %}
                  {{ udoc.displayName }} ({{ udoc.uname }})
                {% else %}
                  {{ udoc.uname }}
                {% endif %}


                {% if udoc.badge %}
                {% set _badge = udoc.badge.split('#') %}
                <a href="{{ url('badge_detail', id=udoc.badgeId) }}" class="user-profile-badge v-center" style="background-color:#{{ _badge[1] }}{% if _badge[2] %};color:#{{ _badge[2] }}{% endif %}" {%if _badge[3] %} data-tooltip="{{ _badge[3] }}" {% endif %} >{{ _badge[0] }}</a>
                {% endif %}

              </h1>
              <p>
                {{ _('UID') }}: {{ udoc['_id'] }}
              </p>

              {% if udoc['coin_all'] > 0 %}
              <p>
                当前硬币数量: {{ udoc['coin_now'] }} （累计获取硬币数量：{{ udoc['coin_all'] }}）:
                <a class="profile-header__contact-item" href="{{ url('coin_bill') }}?uid={{ udoc['_id'] }}" target="_blank"
                  data-tooltip="查看硬币明细">
                  <span class="icon icon-search "></span>
                </a>
              </p>
              {% else %}
              <p> 暂未获得硬币 </p>
              {% endif %}

              <hr />

              <p>
                {{ _('Registered at') }} {{ datetimeSpan(udoc['regat'])|safe }},
                {{ _('last login at') }} {{ datetimeSpan(udoc['loginat'])|safe }},
              {% if sdoc and sdoc.updateAt %}
                {{ _('last active at') }} {{ datetimeSpan(sdoc['updateAt'])|safe if Date.now() - sdoc.updateAt.getTime() > 300000 else _('just now') }}.
              {% else %}
                {{ _('currently offline') }}.
              {% endif %}
              </p>
              <p>{{ _('Solved {0} problems, RP: {1} (No. {2})').format(udoc.nAccept|default(0), udoc['rp']|default(0.0)|round(2), udoc['rank']|default('?')) }}</p>
              {% if udoc._id != 1 and not udoc.hasPriv(PRIV.PRIV_USER_PROFILE) %}
                <p>{{ _('This user was banned.') }}</p>
              {% endif %}
              <div class="profile-header__contact-bar">
              {% if isSelfProfile %}
                <a class="profile-header__contact-item" href="{{ url('home_settings', category='account') }}" data-tooltip="{{ _('Edit Profile') }}">
                  <span class="icon icon-edit"></span>
                </a>
              {% endif %}
                <a class="profile-header__contact-item" href="{{ url('home_messages', query={target:udoc._id}) }}" target="_blank" data-tooltip="{{ _('Send Message') }}">
                  <span class="icon icon-comment--multiple"></span>
                </a>
              {% if udoc['mail'] %}
                <a class="profile-header__contact-item" href="javascript:;" data-copy="{{ udoc['mail'] | base64_encode }}" data-tooltip="{{ _('Copy Email') }}">
                  <span class="icon icon-mail"></span>
                </a>
              {% endif %}
              {% if udoc['qq'] %}
                <a class="profile-header__contact-item" href="javascript:;" data-copy="{{ udoc['qq'] | base64_encode }}" data-tooltip="{{ _('Copy QQ Number') }}">
                  <span class="icon icon-qq"></span>
                </a>
              {% endif %}
              {% if udoc['wechat'] %}
                <a class="profile-header__contact-item" href="javascript:;" data-copy="{{ udoc['wechat'] | base64_encode }}" data-tooltip="{{ _('Copy WeChat Account') }}">
                  <span class="icon icon-wechat"></span>
                </a>
              {% endif %}
              {% if udoc.gender and udoc.gender != model.builtin.USER_GENDER_OTHER %}
                <span
                  class="profile-header__contact-item"
                  data-tooltip="{{ model.builtin.USER_GENDER_RANGE[udoc.gender] }}"
                >
                  {{ model.builtin.USER_GENDER_ICONS[udoc.gender] }}
                </span>
              {% endif %}
              {% if udoc.hasPriv(PRIV.PRIV_MOD_BADGE) %}
                <span
                  class="profile-header__contact-item user-profile-badge badge--su"
                  data-tooltip="{{ _('{0} is a superuser.').format(_('She' if udoc.gender == 1 else 'He')) }}"
                >
                  SU
                </span>
              {% elif udoc.hasPerm(perm.PERM_MOD_BADGE) %}
                <span
                  class="profile-header__contact-item user-profile-badge badge--mod"
                  data-tooltip="{{ _('{0} is a moderator of this domain.').format(_('She' if udoc.gender == 1 else 'He')) }}"
                >
                  MOD
                </span>
              {% endif %}
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="profile-content">
        <div class="section__tab-container immersive">
          <ul class="section__tabs">
            <li class="section__tab-item">
              <h1 class="section__tab-title">{{ _('Bio') }}</h1>
              <div class="section__tab-main">
              {% if not (udoc.bio and ( isSelfProfile or handler.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM))) %}
                {{ nothing.render("This person is lazy and didn't write anything.") }}
              {% else %}
                <div class="section__body typo richmedia">
                  {{ udoc.bio|default('')|markdown|safe }}
                </div>
              {% endif %}
              </div>
            </li>
            {% if pdocs.length %}
              <li class="section__tab-item">
                <h1 class="section__tab-title">{{ _('Accepted Problems') }}</h1>
                <div class="section__tab-main">
                  <div class="typo section__body no-media">
                    {% set _mark = Math.ceil(pdocs.length/4) %}
                    {% macro col(pdocs) %}
                      <div class="medium-3 columns"><ul>
                        {% for pdoc in pdocs %}
                          <li>{{ problem.render_problem_title(pdoc, show_tags=false, small=true) }}</li>
                        {% endfor %}
                      </ul></div>
                    {% endmacro %}
                    <div class="row">
                      {{ col(pdocs.slice(0, _mark)) }}
                      {{ col(pdocs.slice(_mark, _mark*2)) }}
                      {{ col(pdocs.slice(_mark*2, _mark*3)) }}
                      {{ col(pdocs.slice(_mark*3)) }}
                    </div>
                  </div>
                </div>
              </li>
            {% endif %}
            {% for page in findSubModule('partials/user_detail/') %}{% include page %}{% endfor %}
          </ul>
        </div>
      </div>
    </div>
  </div>
  <div class="medium-3 columns">
    {% if isSelfProfile %}
      {{ home.render_sidebar() }}
    {% endif %}
    <div class="section side">
      <div class="section__body">
        <div class="balancer sidebar-user-stat">
          <div class="balancer__body">
            <div class="numbox">
              <div class="numbox__num medium">{{ udoc.nSubmit or 0 }}</div>
              <div class="numbox__text">{{ _('Submitted') }}</div>
            </div>
          </div>
          <div class="balancer__body">
            <div class="numbox">
              <div class="numbox__num medium">{{ udoc.nAccept or 0 }}</div>
              <div class="numbox__text">{{ _('Accepted') }}</div>
            </div>
          </div>
          <div class="balancer__body">
            <div class="numbox">
              <div class="numbox__num medium">{{ udoc.nLike or 0 }}</div>
              <div class="numbox__text">{{ _('Solutions Liked') }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    {% if tags.length %}
      <div class="section side">
        <div class="section__header">
          <h2 class="section__title">{{ _('Problem Tags') }}</h2>
        </div>
        <div class="typo section__body no-media">
          <dl class="exlarge horizontal">
            {% for tag in tags %}
              <dt>{{ tag[0] }}</dt>
              <dd>{{ tag[1] }}</dd>
            {% endfor %}
          </dl>
        </div>
      </div>
    {% endif %}
  </div>
</div>
{% endblock %}